/*
 * @Description: 全宗表格组件
 * @Author: Rfan
 * @Date: 2022-01-07 15:20:55
 * @LastEditTime: 2022-09-08 14:34:02
 */

import { useEffect, useState } from 'react';
import { useMetadataContext } from '../contexts/MetaContext';
import MetadataPane from './MetadataPane';
import type { ICoordinate } from '@/interfaces/global';

const List = () => {
  const { selectAT, selectLevel } = useMetadataContext();

  // 请求参数（坐标）
  const [query, setQuery] = useState<ICoordinate>(null);

  useEffect(() => {
    if (
      (selectAT?.atType || selectAT?.atType === 0) &&
      (selectLevel?.level || selectLevel?.level === 0)
    ) {
      setQuery({
        atType: selectAT.atType,
        atCode: selectAT.atCode,
        level: selectLevel.level
      });
    }
  }, [selectAT, selectLevel]);

  return (
    <MetadataPane
      title={selectLevel?.levelName ? `${selectAT?.atName}-${selectLevel?.levelName} ` : ''}
      data={query}
    />
  );
};

export default List;
